package tuio.components;

import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;

import tuio.I_TouchListener;
import tuio.SpecialTouchEvent;
import tuio.TCurAndPoint;

/**
 * @author Charles Perin
 * 29 mars 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 *
 */
public class PanelTouch extends JPanel implements I_TouchListener{

	private static final long serialVersionUID = 5226279570783599049L;

	public PanelTouch(){
		super();
	}


	@Override
	public void touchPressed(TCurAndPoint tCurAndPoint) {
		MouseEvent evt = new MouseEvent(this, MouseEvent.MOUSE_PRESSED, 0, InputEvent.BUTTON1_MASK, tCurAndPoint.getLocalPoint().x, tCurAndPoint.getLocalPoint().y, 1, false);
		dispatchEvent(evt);
	}

	@Override
	public void touchReleased(TCurAndPoint tCurAndPoint) {
		MouseEvent evt = new MouseEvent(this, MouseEvent.MOUSE_RELEASED, 0, InputEvent.BUTTON1_MASK, tCurAndPoint.getLocalPoint().x, tCurAndPoint.getLocalPoint().y, 1, false);
		dispatchEvent(evt);
	}

	@Override
	public void touchDragged(TCurAndPoint tCurAndPoint) {
		MouseEvent evt = new MouseEvent(this, MouseEvent.MOUSE_DRAGGED, 0, InputEvent.BUTTON1_MASK, tCurAndPoint.getLocalPoint().x, tCurAndPoint.getLocalPoint().y, 1, false);
		dispatchEvent(evt);
	}

	@Override
	public void touchClicked(TCurAndPoint tCurAndPoint) {
		MouseEvent evt;
		evt = new MouseEvent(this, MouseEvent.MOUSE_ENTERED, 0, InputEvent.BUTTON1_MASK, tCurAndPoint.getLocalPoint().x, tCurAndPoint.getLocalPoint().y, 1, false);
		dispatchEvent(evt);
		evt = new MouseEvent(this, MouseEvent.MOUSE_PRESSED, 0, InputEvent.BUTTON1_MASK, tCurAndPoint.getLocalPoint().x, tCurAndPoint.getLocalPoint().y, 1, false);
		dispatchEvent(evt);
		evt = new MouseEvent(this, MouseEvent.MOUSE_CLICKED, 0, InputEvent.BUTTON1_MASK, tCurAndPoint.getLocalPoint().x, tCurAndPoint.getLocalPoint().y, 1, false);
		dispatchEvent(evt);
		evt = new MouseEvent(this, MouseEvent.MOUSE_RELEASED, 0, InputEvent.BUTTON1_MASK, tCurAndPoint.getLocalPoint().x, tCurAndPoint.getLocalPoint().y, 1, false);
		dispatchEvent(evt);
		evt = new MouseEvent(this, MouseEvent.MOUSE_EXITED, 0, InputEvent.BUTTON1_MASK, tCurAndPoint.getLocalPoint().x, tCurAndPoint.getLocalPoint().y, 1, false);
		dispatchEvent(evt);
		
	}
	

	@Override
	public void touchDoubleClicked(TCurAndPoint tCurAndPoint) {
		MouseEvent evt = new MouseEvent(this, MouseEvent.MOUSE_CLICKED, 0, InputEvent.BUTTON1_MASK, tCurAndPoint.getLocalPoint().x, tCurAndPoint.getLocalPoint().y, 2, false);
		dispatchEvent(evt);
	}

	@Override
	public void doubleTouchPressed(TCurAndPoint tCurAndPoint1, TCurAndPoint tCurAndPoint2) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doubleTouchReleased(TCurAndPoint tCurAndPoint1,
			TCurAndPoint tCurAndPoint2) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doubleTouchDragged(TCurAndPoint tCurAndPoint1,
			TCurAndPoint tCurAndPoint2) {
		// TODO Auto-generated method stub
		
	}
	

	@Override
	public void longTouch(TCurAndPoint tCurAndPoint) {
		MouseEvent evt = new SpecialTouchEvent(this, MouseEvent.MOUSE_PRESSED, 0, 0, tCurAndPoint.getLocalPoint().x, tCurAndPoint.getLocalPoint().y, 1, false, SpecialTouchEvent.LONG_TOUCH);
		dispatchEvent(evt);
	}


}
